package com.echo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.echo.activity.R;
import com.echo.model.DayData;
import com.echo.util.DateUtil;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by EchoGe on 2016/6/13.
 */
public class HistoryRecordAdapter extends RecyclerView.Adapter<HistoryRecordAdapter.ViewHolder>{

    private Context mContext;

    private List<DayData> mDayData=new ArrayList();

    private OnRecordClickListener onRecordClickListener;

    public HistoryRecordAdapter(){}

    public HistoryRecordAdapter(Context context){
        this.mContext=context;
    }

    public HistoryRecordAdapter(Context context,List dayData){
        this.mContext=context;
        this.mDayData=dayData;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView dateView;
        public String date;

        public ViewHolder(View itemView) {
            super(itemView);
            dateView= (TextView) itemView.findViewById(R.id.history_record_date);

        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history_record,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        view.setTag(viewHolder);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onRecordClickListener!=null)
                    onRecordClickListener.onRecordDetail((ViewHolder) v.getTag());
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.date=mDayData.get(position).getDate();
        holder.dateView.setText(DateUtil.getDateStr1(holder.date));
    }

    @Override
    public int getItemCount() {
        return mDayData.size();
    }

    public interface OnRecordClickListener{
        public void onRecordDetail(ViewHolder viewHolder);
    }

    public void setOnRecordClickListener(OnRecordClickListener onRecordClickListener){
        this.onRecordClickListener=onRecordClickListener;
    }
}
